package com.sinitek.demo.library.controller;

import com.sinitek.common.support.RequestResult;
import com.sinitek.demo.library.dto.BookDTO;
import com.sinitek.demo.library.dto.ContributeBookDTO;
import com.sinitek.demo.library.service.ILibraryBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 王志华
 * @date 2021/6/18
 */
@RequestMapping("/demo/library/book")
@Api(tags = "图书馆接口")
@RestController
@Slf4j
public class LibraryBookController {
    @Autowired
    private ILibraryBookService libraryBookService;

    @GetMapping("/list")
    @ApiOperation("查询图书")
    public RequestResult<List<BookDTO>> list() {
        List<BookDTO> data = this.libraryBookService.findBooks();
        return RequestResult.success(data);
    }

    @PostMapping("/contribute")
    @ApiOperation("捐赠图书")
    public RequestResult<List<BookDTO>> contribute(@RequestBody ContributeBookDTO contributeBookDTO) {
        this.libraryBookService.contribute(contributeBookDTO);

        return RequestResult.success();
    }
}
